home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Source / 20-NetworkServices / dns / resolver-config.frm.z / resolver-config.frm
Encoding:
Text File  |  1997-07-30  |  9.4 KB  |  273 lines

  1. #!/usr/bin/perl5
  2. #
  3. # resolver-config.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: resolver-config.frm,v 1.25 1997/04/17 21:26:11 shotes Exp $
  21.  
  22. BEGIN { require "/usr/WebFace/lib/CGI.pm"; import CGI; }
  23. require "/usr/OnRamp/lib/OnRamp.pm";
  24. require "/usr/OnRamp/lib/java.pm";
  25.  
  26. $query = new CGI;
  27.  
  28. $resolv_cf = "/etc/resolv.conf";
  29. $title = "Name Resolver";
  30.  
  31. @order = ("nis", "bind", "local", "none");
  32.  
  33. $js =
  34. "$js_standard
  35. $js_error_box
  36. $js_ip
  37. $js_hostname
  38. function checkForm(form) {
  39.     if (!testNameServer(form.nmsrv1) 
  40.         || !testNameServer(form.nmsrv2) 
  41.         || !testNameServer(form.nmsrv3)) return (false);
  42.     if (!testHostname(form.dmsrch1, form.dmsrch1.value, \"domain name\", 1) 
  43.         || !testHostname(form.dmsrch2, form.dmsrch2.value, \"domain name\", 1) 
  44.         || !testHostname(form.dmsrch3, form.dmsrch3.value, \"domain name\", 1) 
  45.         || !testHostname(form.dmsrch4, form.dmsrch4.value, \"domain name\", 1) 
  46.         || !testHostname(form.dmsrch5, form.dmsrch5.value, \"domain name\", 1) 
  47.         || !testHostname(form.dmsrch6, form.dmsrch6.value, \"domain name\", 1)) 
  48.             return (false);
  49.     return (true);
  50. }
  51. function testNameServer(Ctrl) {
  52.     if (Ctrl.value == \"\") return (true);
  53.     if (!testIPaddress(Ctrl.value,false)) { 
  54.         errorBox (Ctrl, \"The name server address \" 
  55.             + Ctrl.value + \"\\nis invalid.\"); 
  56.         return (false); 
  57.     }
  58.     return (true);
  59. }";
  60.  
  61. print $query->header;
  62.  
  63. if (-r $resolv_cf) { &get_resolv; }
  64.  
  65. if ($query->param) { 
  66.     $help = $document_root . $ENV{"SCRIPT_NAME"};
  67.     $help =~ s/cgi$/hlp/;
  68.     exec $help if ($query->param('help') eq "Help");
  69.  
  70.     if ($query->param('doit') eq 'Ok') {
  71.         &formValidation; 
  72.         &makeChanges; }
  73. }
  74.  
  75. &generic;
  76.  
  77. sub formValidation {
  78.     my($count, $which);
  79.  
  80.     foreach $count (1..3) {
  81.         $which = $query->param("nmsrv$count");
  82.         &error("Invalid name server IP address #$count.")
  83.             if $which && &check_ipaddr($which); 
  84.     }
  85.  
  86.     foreach $count (1..6) {
  87.         $which = $query->param("dmsrch$count");
  88.         &error("Invalid domain name #$which.") 
  89.             if $which && &check_hostname($which);
  90.     }
  91. }
  92.  
  93. sub error {
  94.     &error_block($_[0]);
  95.     &generic;
  96.     exit 0;
  97. }    
  98.  
  99. sub makeChanges {
  100.      $message = "The requested changes have been made.";
  101.  
  102.     open(OUT,"> $resolv_cf");
  103.     print OUT "search ",$query->param('dmsrch1')," ",
  104.         $query->param('dmsrch2')," ",$query->param('dmsrch3')," ",
  105.         $query->param('dmsrch4')," ",$query->param('dmsrch5')," ",
  106.         $query->param('dmsrch6'),"\n";
  107.     print OUT "hostresorder";
  108.     if ($query->param('hres1') ne 'none') 
  109.         { print OUT " ", $query->param('hres1'); }
  110.     if ($query->param('hres2') ne 'none') 
  111.         { print OUT " ", $query->param('hres2'); }
  112.     if ($query->param('hres3') ne 'none') 
  113.         { print OUT " ", $query->param('hres3'); }
  114.     print OUT "\n\n";
  115.     if ($query->param('nmsrv1')) { 
  116.         print OUT "nameserver ",$query->param('nmsrv1'),"\n"; }
  117.     if ($query->param('nmsrv2')) { 
  118.         print OUT "nameserver ",$query->param('nmsrv2'),"\n"; }
  119.     if ($query->param('nmsrv3')) { 
  120.         print OUT "nameserver ",$query->param('nmsrv3'),"\n"; }
  121.     close(OUT);
  122. }
  123.  
  124. sub get_resolv {
  125.     $havenfs = system ("/etc/havenfs");
  126.     if ($havenfs == 0) { @ch_order = ("bind","local","none","none"); }
  127.     else { @ch_order = ("nis","bind","local","none"); }
  128.     open(RESOLV, $resolv_cf);
  129.     while (<RESOLV>) {
  130.     if (/^\s*[#\n]/) {
  131.         next;
  132.     }
  133.     chop;
  134.     @entlist = split(/\s+/);
  135.     if ($entlist[0] eq "hostresorder") {
  136.         @ch_order = ("none","none","none","none");
  137.         for ($i = 1; $i <= $#entlist; $i++) {
  138.         if ( ($entlist[$i] ne "nis") && ($entlist[$i] ne "bind") &&
  139.              ($entlist[$i] ne "local") ) {
  140.             print "<p>Illegal option $entlist[$i] in $resolv_cf.";
  141.             if ($havenfs == 0) { @ch_order = ("bind","local","none","none"); }
  142.             else { @ch_order = ("nis","bind","local","none"); }
  143.             last;
  144.         }
  145.         if ( ($entlist[$i] eq "nis") && ($havenfs != 0) ) {
  146.             $shift_list = 1; 
  147.             next;
  148.         }
  149.         $ch_order[$i-1] = $entlist[$i];
  150.         }
  151.         shift @ch_order if ($shift_list);
  152.     }
  153.     elsif ($entlist[0] eq "nameserver") {
  154.         $nmserver[$#nmserver+1] =  $entlist[1];
  155.     }
  156.     elsif ($entlist[0] eq "domain") {
  157.         $dmname = $entlist[1];
  158.     }
  159.     elsif ($entlist[0] eq "search") {
  160.         for ($i = 1; $i <= $#entlist, $i <= 6; $i++) {
  161.         $dmsearch[$i-1] =  $entlist[$i];
  162.         }
  163.     }
  164.     else {
  165.         print "<p>Illegal option $entlist[0] in $resolv_cf.";
  166.         last;
  167.     }
  168.     }
  169.     close(RESOLV);
  170. }  
  171.  
  172. sub generic {
  173.     &js_title_block($title,$js);
  174.     &header_block($title);
  175.  
  176.     print $query->startform("POST", "", "", "NAME=StandardForm", "onSubmit=\"return runSubmit()\"");
  177.  
  178.     print "<i>$message</i>";
  179.  
  180.     print "<h3>Order of services for name and address resolution:</h3>\n";
  181.  
  182.     print "<font size=\"+1\"><center><table cellpadding=5 width=450>\n";
  183.     print "<tr><th>First<th>Next<th>Last</tr>\n";
  184.  
  185.     print "<tr><td align=center>", $query->popup_menu(-name=>'hres1',
  186.                         -values=>\@order,
  187.                         -default=>$ch_order[0]);
  188.     print "\n<td align=center>", $query->popup_menu(-name=>'hres2',
  189.                         -values=>\@order,
  190.                         -default=>$ch_order[1]);
  191.     print "\n<td align=center>", $query->popup_menu(-name=>'hres3',
  192.                         -values=>\@order,
  193.                         -default=>$ch_order[2]);
  194.     print "</tr></table></center>";
  195.  
  196.     print "<h3>Addresses of DNS servers to do name resolution: </h3><center>";
  197.  
  198.     print "<table cellpadding=5 width=450>\n";
  199.  
  200.     print "<tr><td align=center><strong>1</strong> ",
  201.           $query->textfield(-name=>'nmsrv1',
  202.                 -default=>$nmserver[0],
  203.                 -size=>13,
  204.                 -maxlength=>16);
  205.     print "\n<td align=center><strong>2</strong> ",
  206.           $query->textfield(-name=>'nmsrv2',
  207.                 -default=>$nmserver[1],
  208.                 -size=>13,
  209.                 -maxlength=>16);
  210.     print "\n<td align=center><strong>3</strong> ",
  211.           $query->textfield(-name=>'nmsrv3',
  212.                 -default=>$nmserver[2],
  213.                 -size=>13,
  214.                 -maxlength=>16);
  215.     print "\n</tr>";
  216.     print "</table></center></font>";
  217.  
  218.     print "<p>\n";
  219. #    print "The Search list for host-name lookup can be specified below.\n",
  220. #      "The search list is normally determined from the local domain name\n",
  221. #      "by default, it begins with the local domain name, then successive\n",
  222. #      "parent domains that have at least two components in their names.\n",
  223. #      "This can be changed by listing the desired domain search path\n",
  224. #      "following the search keyword with spaces or tabs separating the names.\n",
  225. #      "Most resolver queries are attempted using each component of the search\n",
  226. #      "path in turn until a match is found.  This process can be slow and\n",
  227. #      "generates a lot of network traffic if the servers for the listed\n",
  228. #      "domains are not local.  Queries time out if no server is available for\n",
  229. #      "one of the domains.  The search list is limited to six domains with a\n",
  230. #      "total of 256 characters.  The first item in the list becomes the\n",
  231. #      "default domain name, the remaining items are the other domains to\n",
  232. #      "search after the default one.\n";
  233.  
  234.     print "<h3>List of domains that DNS servers will search:</h3>\n";
  235.     print "<font size=\"+1\"><center><table  cellpadding=5 width=450>\n";
  236.     print "<tr><td align=center><strong>1</strong> ",
  237.           $query->textfield(-name=>'dmsrch1',
  238.                 -default=>$dmsearch[0],
  239.                 -size=>13,
  240.                 -maxlength=>16);
  241.     print "\n<td align=center><strong>2</strong> ",
  242.           $query->textfield(-name=>'dmsrch2',
  243.                 -default=>$dmsearch[1],
  244.                 -size=>13,
  245.                 -maxlength=>16);
  246.     print "\n<td align=center><strong>3</strong> ",
  247.           $query->textfield(-name=>'dmsrch3',
  248.                 -default=>$dmsearch[2],
  249.                 -size=>13,
  250.                 -maxlength=>16),
  251.           "</tr>";
  252.     print "\n<tr><td align=center><strong>4</strong> ",
  253.           $query->textfield(-name=>'dmsrch4',
  254.                 -default=>$dmsearch[3],
  255.                 -size=>13,
  256.                 -maxlength=>16);
  257.     print "\n<td align=center><strong>5</strong> ",
  258.           $query->textfield(-name=>'dmsrch5',
  259.                 -default=>$dmsearch[4],
  260.                 -size=>13,
  261.                 -maxlength=>16);
  262.     print "\n<td align=center><strong>6</strong> ",
  263.           $query->textfield(-name=>'dmsrch6',
  264.                 -default=>$dmsearch[5],
  265.                 -size=>13,
  266.                 -maxlength=>16);
  267.     print "\n</tr></table></center><br>";
  268.  
  269.     print &js_buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"');
  270.  
  271.     print $query->endform;
  272. }
  273.